package org.eztouch.exception;

import javax.servlet.http.HttpServletRequest;

import org.eztouch.dwz.DWZ;
import org.eztouch.dwz.DwzAjax;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * Spring异常拦截器.
 */
@ControllerAdvice
public class WebExceptionHandler {

	private static final Logger log  = LoggerFactory.getLogger(WebExceptionHandler.class);

	/**
	 * 总异常
	 */
	@ExceptionHandler({ Exception.class })
	@ResponseStatus(HttpStatus.OK)
	public String processException(Exception e, HttpServletRequest request) {
		log.error("Exception", e);
		DwzAjax dwz = new DwzAjax();
		dwz.setStatusCode(DWZ.ERROR);
		dwz.setMessage("系统异常");
		request.setAttribute("dwz", dwz);
		return "common/ajaxDone";
	}

}
